package com.example.controller;

import com.example.annotation.AsyncMessageHandler;
import com.example.dto.LoginRequest;
import com.example.dto.LoginResponse;
import com.example.entity.User;
import com.example.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/user")
@Tag(name = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    @AsyncMessageHandler(queue = "user.register.queue")
    public User register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    @AsyncMessageHandler(queue = "user.login.queue")
    public LoginResponse login(@RequestBody LoginRequest request) {
        return userService.login(request);
    }

    @PutMapping("/{id}/status")
    @Operation(summary = "修改用户信息")
    @AsyncMessageHandler(queue = "user.update.queue")
    public boolean updateStatus(@PathVariable Long id, @RequestParam Integer status) {
        return userService.updateStatus(id, status);
    }
}